-- UILoadingEffect
-- Created by huanghr
-- 加载中界面(只显示动画，没有文字)

UILoadingEffect = class("UILoadingEffect", function()
    return cc.Layer:create();
end);

function UILoadingEffect.create()
    return UILoadingEffect.new();
end

-- 构造函数
function UILoadingEffect:ctor()
    -- 初始化
    self:setName("UILoadingEffect");
    local node = cc.CSLoader:createNode("layout/common/CommunicatingForm.csb");
    self:addChild(node);
    self.node = node;

    self:setLocalZOrder(UIMgr.BONUS_NOTIFY_ZORDER + 1);

    -- 重绘
    self:redraw();

    -- 适配
    self:resize();
end

-- 适配
function UILoadingEffect:resize()
    local w = AlignM.frameSize.width;
    local h = AlignM.frameSize.height;
    local node = self.node;

    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");
end

-- 重绘
function UILoadingEffect:redraw()
    -- 不显示文字
    -- self:showCommunicateText();
    self:playWaitingEffect();
end

-- 通信文字
function UILoadingEffect:showCommunicateText()
    -- 处理文字跳动相关函数
    local count = 4;
    local letterNode = findChildByName(self.node, "CT/communicating_label");
    TextStyleM.setTextStyle(letterNode, TextStyleM.TEXT_SIZE_LARGE, TextStyleM.TEXT_COLOR_ORANGE, true);
    local function dealAction(count, letterNode, mainNode)
        local jumpFlag = 1;

        local function jump()
            local a = letterNode;
            local str = getLocStr("loading");
            if jumpFlag == count then
                jumpFlag = 1;
            end
            for i = 1, jumpFlag do
                str = str .. "."
            end
            letterNode:setString(str);
            jumpFlag = jumpFlag + 1;
            performWithDelay(mainNode, jump, 0.2);
        end

        jump();
    end

    dealAction(count, letterNode, self);
end

-- 播放等待特效
function UILoadingEffect:playWaitingEffect()
    local modelNode = findChildByName(self.node, "CT/effect_node");
    local icon = findChildByName(self.node, "CT/effect_icon");

    -- 居中
    modelNode:setPosition(0, 0);

    local function playWaiting()
        modelNode:removeAllChildren();
        playEffect(modelNode, 2054, 0, -10);
        performWithDelay(modelNode, playWaiting, 0.5);
    end
    playWaiting();
end

